package com.sino.operation.service.business;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sino.operation.commons.ConstantValue;
import com.sino.operation.commons.commonEnum.VoucherType;
import com.sino.operation.commons.util.Exec_Util;
import com.sino.operation.entity.BizExchangeInfo;
import com.sino.operation.entity.BizMarginOpenAccount;

import java.util.Map;

/**
 * @Title: Exec_710305_Util
 * @Description:
 * @Author dengls
 * @date 2021/11/2 14:17
 */
public class Exec_710305_Util {
    //将中心录入字段进行登记薄归集
    public static BizMarginOpenAccount CollectionHandle(Map<String, Map> data, BizMarginOpenAccount bizMarginOpenAccount) {
        //定期保证金、活期保证金通用字段
        String zczh = data.containsKey("ZCZH") ? data.get("ZCZH").containsKey("value") ? data.get("ZCZH").get("value").toString() : "" : "";//转出账号
        String zczhhm = data.containsKey("ZCZHHM") ? data.get("ZCZHHM").containsKey("value") ? data.get("ZCZHHM").get("value").toString() : "" : "";//转出账户户名
        String fkrkhh = data.containsKey("FKRKHH") ? data.get("FKRKHH").containsKey("value") ? data.get("FKRKHH").get("value").toString() : "" : "";//付款人开户行名
        String skrmc = data.containsKey("SKRMC") ? data.get("SKRMC").containsKey("value") ? data.get("SKRMC").get("value").toString() : "" : "";//收款人名称
        String skrkhhm = data.containsKey("SKRKHHM") ? data.get("SKRKHHM").containsKey("value") ? data.get("SKRKHHM").get("value").toString() : "" : "";//收款人开户行名
        String zcpzhm = data.containsKey("ZCPZHM") ? data.get("ZCPZHM").containsKey("value") ? data.get("ZCPZHM").get("value").toString() : "" : "";//转出凭证号码
        String khje = data.containsKey("KHJE") ? data.get("KHJE").containsKey("value") ? data.get("KHJE").get("value").toString() : "" : "";//开户金额(交易金额)
        String cprq = data.containsKey("CPRQ") ? data.get("CPRQ").containsKey("value") ? data.get("CPRQ").get("value").toString() : "" : "";//出票日期
        String zfmm = data.containsKey("ZFMM") ? data.get("ZFMM").containsKey("value") ? data.get("ZFMM").get("value").toString() : "" : "";//支付密码
        String qxr = data.containsKey("QXR") ? data.get("QXR").containsKey("value") ? data.get("QXR").get("value").toString() : "" : "";//起息日（默认返显当天）
        String zxll = data.containsKey("ZXLL") ? data.get("ZXLL").containsKey("value") ? data.get("ZXLL").get("value").toString() : "" : "";//执行利率
        String bz = data.containsKey("BZ") ? data.get("BZ").containsKey("value") ? data.get("BZ").get("value").toString() : "" : "";//备注
        String product_type = data.containsKey("PRODUCT_TYPE") ? data.get("PRODUCT_TYPE").containsKey("value") ? data.get("PRODUCT_TYPE").get("value").toString() : "" : "";//产品类型
        bizMarginOpenAccount.setPayAcc(zczh);
        bizMarginOpenAccount.setPayName(zczhhm);
        bizMarginOpenAccount.setPayBname(fkrkhh);
        bizMarginOpenAccount.setRecvName(skrmc);
        bizMarginOpenAccount.setRecvName(skrkhhm);
        bizMarginOpenAccount.setZccerno2(zcpzhm);
        bizMarginOpenAccount.setAmount(khje);
        bizMarginOpenAccount.setCerdate(cprq);
        bizMarginOpenAccount.setPaypwd(zfmm);
        bizMarginOpenAccount.setQxr(qxr);
        bizMarginOpenAccount.setQxr(zxll);
        bizMarginOpenAccount.setRemarks(bz);
        //定期保证金额外字段
        if (ConstantValue.DWDQBZJ.equals(product_type)) {
            //定期保证金单独字段
            String cq = data.containsKey("CQ") ? data.get("CQ").containsKey("value") ? data.get("CQ").get("value").toString() : "" : "";//存期
            String dqr = data.containsKey("DXR") ? data.get("DXR").containsKey("value") ? data.get("DXR").get("value").toString() : "" : "";//到期日（根据存期返显）
            String fxpl = data.containsKey("FXPL") ? data.get("FXPL").containsKey("value") ? data.get("FXPL").get("value").toString() : "" : "";//付息频率
            String zcfs = data.containsKey("ZCFS") ? data.get("ZCFS").containsKey("value") ? data.get("ZCFS").get("value").toString() : "" : "";//转存方式
            String zccq = data.containsKey("ZCCQ") ? data.get("ZCCQ").containsKey("value") ? data.get("ZCCQ").get("value").toString() : "" : "";//转存存期
            bizMarginOpenAccount.setBondterm(cq);
            bizMarginOpenAccount.setDxr(dqr);
            bizMarginOpenAccount.setFxpl(fxpl);
            bizMarginOpenAccount.setZcfs(zcfs);
            bizMarginOpenAccount.setBondterm(zccq);
        }
        return bizMarginOpenAccount;
    }

    //判重
    public static QueryWrapper<BizMarginOpenAccount> repeatJudge(BizMarginOpenAccount bizMarginOpenAccount) {
        QueryWrapper<BizMarginOpenAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("JOURNAL_NO", bizMarginOpenAccount.getJournalNo() == null ? "" : bizMarginOpenAccount.getJournalNo());
        wrapper.eq("AMOUNT", Exec_Util.addPoint(bizMarginOpenAccount.getAmount()) == null ? "" : Exec_Util.addPoint(bizMarginOpenAccount.getAmount()));
        wrapper.eq("TRANS_DATE", bizMarginOpenAccount.getTransDate() == null ? "" : bizMarginOpenAccount.getTransDate());
        wrapper.eq("PAY_ACC", bizMarginOpenAccount.getPayAcc() == null ? "" : bizMarginOpenAccount.getPayAcc());
        wrapper.eq("TRANS_CODE", bizMarginOpenAccount.getTransCode() == null ? "" : bizMarginOpenAccount.getTransCode());
        wrapper.eq("ORGAN_ID", bizMarginOpenAccount.getOrganId() == null ? "" : bizMarginOpenAccount.getOrganId());
        wrapper.eq("SOURCE", bizMarginOpenAccount.getSource() == null ? "" : bizMarginOpenAccount.getSource());
        String voucherType = bizMarginOpenAccount.getCerty();
        //如果凭证种类是支票 或者 电汇 获取凭证号码作为判重依据
        if (VoucherType.VOUCHERTYPE01.getValue().equals(voucherType) || VoucherType.VOUCHERTYPE38.getValue().equals(voucherType)) {
            wrapper.eq("CERTY", bizMarginOpenAccount.getJournalNo() == null ? "" : bizMarginOpenAccount.getCerty().length() > 16 ?
                    bizMarginOpenAccount.getCerty().substring(0, 16) : bizMarginOpenAccount.getCerty());
        }
        return wrapper;
    }
}
